// order-detail
import { PACKAGE_ACTIVITY_PAGE } from '../../../constants/route';
import { TARGET_TYPE } from '../../../constants/common';
import { ORDER_TYPE } from '../../../constants/order';
import { handleOrderStatus } from '../../biztools/order';
import { getStoreOrderDetail } from '../../api/order';
import { OrderDetailMixins } from '../../../behaviors/page';
const { showLoading, hideLoading, } = require('../../../common/env');

Page({
    mixins: [OrderDetailMixins],
    data: {
        targetType: TARGET_TYPE,
        orderType: ORDER_TYPE,
        orderDetail: {},
        orderStatusInfo: {},
        storeId: '',
        activityUrl: '',
    },
    onLoad: function (options) {
        const { orderNumber, storeId } = options;
        this.setData({
            storeId,
        }, async () => {
            await this.refreshOrderDetail(orderNumber);
        });
    },
    refreshOrderDetail: async function (orderNumber) {
        showLoading('加载中...');
        const { storeId } = this.data;
        console.log('ExpanOrderDetail => 订单号为：', orderNumber);
        const orderDetail = await getStoreOrderDetail(orderNumber, storeId);
        console.log('ExpanOrderDetail => 订单详情为：', orderDetail);
        this.setData({
            orderDetail,
            orderStatusInfo: handleOrderStatus(orderDetail),
            activityUrl: `${PACKAGE_ACTIVITY_PAGE['detail']}?activityId=${orderDetail.activityId}`,
        });
        hideLoading();
    },
})